<?php
namespace logInPage;

class LogInPage{
	
	private static $registrerButton = "registrerButton";	
	private static $username = 'username'; 
	private static $password = 'password';
	private static $checkbox = 'rememberMe';
	private static $logInButton = 'logInButton';
	private static $logOutButton = 'logOutButton';
	private static $submitPic = 'submitPic';
	private static $postText = 'postText';
	private static $comments = 'comments';
	private static $deleteComment = 'deleteComment';
	private static $unique = 'deleteComment';
	private static $editComment = 'editComment';
	private static $newComment = 'newComment';
	private static $message = "";
	
	//@return string (username)
	public function getUsername(){
		if(isset($_POST[self::$username])){	
		return $_POST[self::$username];
		}
	}
	
	//@return string(password)
	public function getPassword(){
		if(isset($_POST[self::$password]))
		return $_POST[self::$password];
	}
	public function getCheckbox(){
		if(isset($_POST[self::$checkbox]))
		return TRUE;
	}
	
	//check button
	//@return bool
	public function logInButton(){
		if(isset($_POST[self::$logInButton])){
			if($this->viewCheck() == TRUE){
				return TRUE;		
			}
		}
			return FALSE;
	}
	
	//check button
	//@return bool
	public function logOutButton(){
		if(isset($_POST[self::$logOutButton])){
				return TRUE;		
		}
			return FALSE;
	}
	
	//check button
	//@return bool
	public function registrerButton(){
		if(isset($_POST[self::$registrerButton])){
				return TRUE;		
		}
			return FALSE;
	}
	
	//check button
	//@return bool
	public function submitPicButton(){
		if(isset($_POST[self::$submitPic])){
				return TRUE;		
		}
			return FALSE;
	}
	
	//check button
	//@return bool
	public function commentButton(){
		if(isset($_POST[self::$postText])){
				return TRUE;		
		}
			return FALSE;
	}
	
	//@return string (comments)
	public function getComments(){
		return $_POST[self::$comments];
	}
	
	//@return string (editcomment)
	public function getbuttonValue(){
		return $_POST[self::$postText];
	}
	
	//check button
	//@return bool
	public function deletCommentBtn(){
		if(isset($_POST[self::$deleteComment])){
				return TRUE;		
		}
			return FALSE;
	}
	
	//@return string (uniqueID)
	public function getUnique(){
		return $_POST[self::$unique];
	}
	
	//check button
	//@return bool
	public function getEditButton(){
		if(isset($_POST[self::$editComment])){
			return TRUE;
		}
		return FALSE;
	}
	
	//@return string (editcomment)
	public function getEditId(){
		return $_POST[self::$editComment];
	}
	
	//@return string (new comment)
	public function getnewComment(){
		return $_POST[self::$newComment];
	}
	
	
	//sets message
	public function setMessage($message){
		switch($message){
	        case 1: self::$message = 'Inloggning lyckades';
	        break;
	        case 2: self::$message = 'Registrering lyckades!';
	        break;
	        case 3: self::$message = 'Användarnamn saknas';
	        break;
	        case 4: self::$message = 'Lösenord saknas';
	        break;
	        case 5: self::$message = 'Felaktigt användarnamn och/eller lösenord';
	        break;
	        case 6: self::$message = 'Du har loggats ut';
	        break;
	        case 7: self::$message = "Sessions Tjuv!";
	        break;
	        case 8: self::$message = "Registrering misslyckades! </br> Användarnamn eller lösenord saknas!";
	        break;
	        case 9: self::$message = 'Registrering misslyckades! </br> Användarnamn och/eller lösenord måste innehålla minst 5 tecken';
	        break;
        }
	}
	
	//checks user name and password in view
	//@return bool
	private function viewCheck(){
		if(empty($_POST[self::$username])){
			self::$message = "Användarnamn Saknas! ";
			return FALSE;
		}else if(empty($_POST[self::$password])){
			self::$message = "Lösenord saknas! ";
			return FALSE;
		}
		return TRUE;
	}
	
	//@return string (html header)
	public function loggedInHeader($usernameSession){
		$header = "
				<div id='header'>
					<h1>Inloggad som:  " . $usernameSession . "</h1>
					".self::$message."
					<form class='form-inline' action='index.php?attempt' method='post' role='form'>
						<button id='LogOutButton' name='logOutButton'; type='submit' class='btn btn-default'>Logga ut</button>
					</form>
				</div>
				";
		
		return $header;
	}
	
	//@return string (html)
	public function loggedOutHeader(){
		$header = '
				<div id="header">
					<h1>Ej Inloggad!</h1>
					<h3>Logga in för att ladda upp eller kommentera bilder!</h3>
				</div>
				';
		return $header;
	}
	
	//@return string (html)
	public function getLoggedInPage($message){
		$this->setMessage($message);
		$html = '
				<div id="centercontent">
					<div class="form-group">
				   		 <form action="index.php?attempt.php" method="post" enctype="multipart/form-data">
							Välj Bild! <input type="file" name="photo"/>
							<input type="submit" name="submitPic" value="Skicka" class="btn btn-default"/>
						</form>
					</div>
				</div>
				';
				
		return $html;
	}
	
	//@return string (html)
	public function getLoggedOutPage($message){
		$this->setMessage($message);
		$usernamevalue = $this->getUsernameValue();    
		$logInHtml = "
					<div id='centercontent'>
					".self::$message."
					<h3>Logga In</h3>
					<form class='form-inline' action='index.php?attempt' method='post' role='form'>
						<div class='form-group'>
					    	<label class='sr-only' for='Username'>Username</label>
					    	<input type='text' class='form-control' name='username' id='Username' value='$usernamevalue' placeholder='Användarnamn'>
					  	</div>
					  	<div class='form-group'>
					    	<label class='sr-only' >Lösenord</label>
					    	<input type='password' class='form-control' name='password' placeholder='Lösenord'>
					  	</div>
						<button id='LogInButton' name='logInButton' type='submit' class='btn btn-default'>Logga In</button>
					</form>
					
					<div id='registrer'>
						<h3>Registrera</h3>
						<form class='form-inline' action='index.php?attempt' method='post' role='form'>
							<div class='form-group'>
						    	<label class='sr-only' for='Username1'>Username</label>
						    	<input type='text' class='form-control' name='username' id='Username1' placeholder='Användarnamn'>
						  	</div>
						  	<div class='form-group'>
						    	<label class='sr-only'>Lösenord</label>
						    	<input type='password' class='form-control' name='password' placeholder='Lösenord'>
						  	</div>
							<button id='registrerButton' name='registrerButton' type='submit' class='btn btn-default'>Registrera</button>
						</form>
					</div>
					</div>
			 		";			
		return $logInHtml;
	}	
	
	//@return string (username)
	private function getUsernameValue(){
		$usernamevalue = '';
		if(isset($_POST[self::$username])){
			$usernamevalue =$_POST[self::$username]; 
		}
		return $usernamevalue;
	}
}


